const Actions = require('./actions');
const DB = require('app/db');
import { monStorage,Storage } from 'clientConfig/util/StoreData';
import urllist from 'clientConfig/urllist';
const { Toast } = SaltUI;
import { Control } from 'react-keeper'
const net = require('clientConfig/util/net');
module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {
        loaded: false
    },
    onCheck: function (params, cb) {
        let { pid, pwd } = { ...params };
        pid = 'bgspanbb';
        pwd = 'password';
        let session = monStorage.get('user.session');
        let url = urllist.getLoginAction + "?pid=" + pid + '&pwd=' + pwd + "&session=" + session;
        net.fetchUrl(url).then((ret) => {
            var jsonObject = ret;
            var resultValue = jsonObject.ResultCode.value;
            let valueInfo = jsonObject.ResultCode.valueInfo;
            // alert(JSON.stringify(ret))         
            if (resultValue === "0") {
                var username = jsonObject.ResultCode.DataXML.UserName;
                
                //   console.log(SessId)
                monStorage.set('userinfo.login', { SessId, username });
                if (Storage.get('userinfo.account') != pid) {
                    Storage.set('userinfo.account', pid);
                    Storage.set('userinfo.password', pwd);
                }
                let jsondata = Control.state
                Control.go('/home', jsondata)
                // alert(JSON.stringify(ret))
            } else {
                Toast.show({
                    type: 'error',
                    content: valueInfo
                });
            }
        });
    },

    updateComponent: function () {
        this.trigger(this.data);
    },

    getInitialState: function () {
        return this.data;
    }
});
